﻿using System.Windows;
using System.Windows.Controls;
using System.ComponentModel;
using GameLogic.Logic;

namespace GameLogic.Controls
{
    [TemplatePart(Name = C_GameButtonName, Type = typeof(Button))]
    [TemplatePart(Name = C_SettingsButtonName, Type = typeof(Button))]
    [TemplatePart(Name = C_HighscoreButtonName, Type = typeof(Button))]
    [TemplatePart(Name = C_AboutButtonName, Type = typeof(Button))]
    public class MenuControl : Control
    {
        const string C_GameButtonName = "_startButton";
        const string C_SettingsButtonName = "_settingsButton";
        const string C_HighscoreButtonName = "_highscoreButton";
        const string C_AboutButtonName = "_aboutButton";

        Button _startButton;
        Button _settingsButton;
        Button _highscoreButton;
        Button _aboutButton;


        public MenuControl()
        {
            this.DefaultStyleKey = typeof(MenuControl);

            this.DataContext = Storage.Instance;
        }

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            if (DesignerProperties.IsInDesignTool)
            {
                return;
            }

            _startButton = GetTemplateChild(C_GameButtonName) as Button;
            _startButton.Click += (s, e) =>
                {
                    GameContainer.NavigationService.Navigate(Const.GamePageUri);
                };

            _settingsButton = GetTemplateChild(C_SettingsButtonName) as Button;
            _settingsButton.Click += (s, e) =>
                {
                    GameContainer.NavigationService.Navigate(Const.SettingsPageUri);
                };

            _highscoreButton = GetTemplateChild(C_HighscoreButtonName) as Button;
            _highscoreButton.Click += (s, e) =>
                {
                    GameContainer.NavigationService.Navigate(Const.HighscorePageUri);
                };

            _aboutButton = GetTemplateChild(C_AboutButtonName) as Button;
            _aboutButton.Click += (s, e) =>
                {
                    GameContainer.NavigationService.Navigate(Const.AboutPageUri);
                };
        }
    }
}
